/*
 * @Author: liuhandong
 * @Date: 2020-12-02 23:45:05
 */
using UnityEngine;

public class SSRCameraEffect : MonoBehaviour
{
    public Material material;
    private Camera mCachedCamera;
    private void Awake()
    {
        mCachedCamera = GetComponent<Camera>();
        mCachedCamera.depthTextureMode = DepthTextureMode.DepthNormals;
    }

    private void OnRenderImage(RenderTexture src, RenderTexture dest) 
    {
        //Texture depth = Shader.GetGlobalTexture("_CameraDepthNormalsTexture");
        //material.SetTexture("_CameraDepthNormalsTexture11", depth);
        material.SetMatrix("_CameraMatrix", mCachedCamera.worldToCameraMatrix);
        material.SetMatrix("_CameraMatrixInv", mCachedCamera.worldToCameraMatrix.inverse); 
        var mat = mCachedCamera.worldToCameraMatrix.inverse;
        var mat2 = transform.localToWorldMatrix;
        var inv = mCachedCamera.projectionMatrix.inverse;
        material.SetMatrix("_InvProjectMatrix", inv);
        material.SetMatrix("_ProjectMatrix",  mCachedCamera.projectionMatrix);
        Vector4 param = Shader.GetGlobalVector("_ProjectionParams");
        Debug.Log(param);
        Graphics.Blit(src, dest, material);
    }
}